
Ext.onReady(function(){
    var win, form;

		form= Ext.create('Ext.form.Panel', {
			//title: 'Simple Form',
			//bodyPadding: 5,
			//width: 350,

			// The form will submit an AJAX request to this URL when submitted
			//url: 'index.php/usuario/loguear',
			url: 'j_spring_security_check',

			// Fields will be arranged vertically, stretched to full width
			layout: 'anchor',
			defaults: {
				anchor: '100%'
			},

			// The fields
			defaultType: 'textfield',
			items: [{
				fieldLabel: 'Usuario',
				name: 'j_username',
				allowBlank: false
			},{
				fieldLabel: 'Password',
				name: 'j_password',
				inputType:'password',
				allowBlank: false
			}]
		});




        //if (!win) {
            win = Ext.create('Ext.Window', {
                title: 'Layout Window',
                closable: false,
				resizable : false,
				draggable : false,
                //closeAction: 'hide',
                width: 350,
                //minWidth: 350,
                height: 150,
                /*layout: {
                    type: 'border',
                    padding: 5
                },*/
                items: form,
				//html:'Hola mundo!',
				buttonAlign : 'center',
				buttons: [{ 
					text: 'Ingresar' ,
					handler: function() {
						form.getForm().submit({
							
							success: function(){
				                Ext.Msg.alert('Status', 'Authentication Successful', function(btn, text){

				                    if (btn == 'ok'){
				                        window.location = 'indexapp.jsp';
				                    }
				                });

				            },
							failure: function(form, action) { //alert("fracaso");
								//console.info(action);
								Ext.Msg.alert('Error de autenticacion', action.result.msg);
							}
						});
					}
				}
				]
            });
        //}
		
		win.show();
/*
        if (win.isVisible()) {
            win.hide(this, function() {

            });
        } else {
            win.show(this, function() {
                
            });
        }
*/
});